import type { AddAddressItem } from '@/types/address'
import { http } from '@/utils/request'

/**
 * 添加收货地址
 * @param data 请求参数
 */
export const addMemberAddress = (data: AddAddressItem) => {
  return http({
    url: '/member/address',
    method: 'POST',
    data
  })
}

/**
 * 获取收货地址列表
 */
export const getMemberAddressAPI = () => {
  return http<AddAddressItem[]>({
    url: '/member/address',
    method: 'GET'
  })
}

/**
 * 获取收货地址详情
 * @param id 收货地址id
 */
export const getMemberAddressDetailAPI = (id: string) => {
  return http<AddAddressItem>({
    url: `/member/address/${id}`,
    method: 'GET'
  })
}

export const putMemberAddressAPI = (id: string, data: AddAddressItem) => {
  return http({
    url: `/member/address/${id}`,
    method: 'PUT',
    data
  })
}

/**
 * 删除收货地址
 * @param id 地址id(路径参数)
 */
export const deleteMemberAddressByIdAPI = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/member/address/${id}`
  })
}
